# Copyright 2014-2015 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  

# Test PowerPC instructions disassembly.

standard_testfile .s
set objfile [standard_output_file ${testfile}.o]

if {![istarget "powerpc*-*-*"]} then {
    verbose "Skipping PowerPC instructions disassembly."
    return
}

if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${objfile}" object {debug}] != "" } {
    untested "PowerPC instructions disassembly"
    return -1
}

clean_restart ${objfile}

# Disassemble the function.

set test "disass func"
gdb_test_multiple $test $test {
    -re "\r\nDump of assembler code for function func:(\r\n.*\r\n)End of assembler dump.\r\n$gdb_prompt $" {
	set func $expect_out(1,string)
	pass $test
    }
}

proc instr_to_patt {offset instr} {
    # 0x0000000000000018 <+24>:	stxvd2x vs43,r4,r5
    return ".*\r\n\[ \t\]*0x\[0-9a-f\]+ <\\$offset>:\[ \t\]*[string map [list { } "\[ \t\]+" . {\.}] $instr]\[ \t\]*\r\n.*"
}

proc func_check {offset instr} {
    global func

    set test "Found $offset: $instr"
    if [regexp -nocase -line [instr_to_patt $offset $instr] $func] {
	pass $test
    } else {
	fail $test
    }
}

func_check +0    "lxvd2x  vs3,r4,r5"
# Some instructions are no longer recognized, this is correct since:
# [PATCH] Remove support for POWER7 VSX load/store with update instructions
# http://sourceware.org/ml/binutils/2009-09/msg00680.html
# http://sourceware.org/ml/binutils-cvs/2009-09/msg00331.html
# lxvd2ux vs3,r4,r5
func_check +4    ".long 0x7c642ed8"
func_check +8    "lxvd2x  vs43,r4,r5"
# lxvd2ux vs43,r4,r5
func_check +12   ".long 0x7d642ed9"
func_check +16   "stxvd2x vs3,r4,r5"
# stxvd2ux vs3,r4,r5
func_check +20   ".long 0x7c642fd8"
func_check +24   "stxvd2x vs43,r4,r5"
# stxvd2ux vs43,r4,r5
func_check +28   ".long 0x7d642fd9"
func_check +32   "xxmrghd vs3,vs4,vs5"
func_check +36   "xxmrghd vs43,vs44,vs45"
func_check +40   "xxmrgld vs3,vs4,vs5"
func_check +44   "xxmrgld vs43,vs44,vs45"
func_check +48   "xxmrghd vs3,vs4,vs5"
func_check +52   "xxmrghd vs43,vs44,vs45"
func_check +56   "xxmrgld vs3,vs4,vs5"
func_check +60   "xxmrgld vs43,vs44,vs45"
func_check +64   "xxpermdi vs3,vs4,vs5,1"
func_check +68   "xxpermdi vs43,vs44,vs45,1"
func_check +72   "xxpermdi vs3,vs4,vs5,2"
func_check +76   "xxpermdi vs43,vs44,vs45,2"
func_check +80   "xvmovdp vs3,vs4"
func_check +84   "xvmovdp vs43,vs44"
func_check +88   "xvmovdp vs3,vs4"
func_check +92   "xvmovdp vs43,vs44"
func_check +96   "xvcpsgndp vs3,vs4,vs5"
func_check +100  "xvcpsgndp vs43,vs44,vs45"
func_check +104  "wait"
func_check +108  "wait"
func_check +112  "waitrsv"
func_check +116  "waitrsv"
func_check +120  "waitimpl"
func_check +124  "waitimpl"
func_check +128  "doze"
func_check +132  "nap"
func_check +136  "sleep"
func_check +140  "rvwinkle"
func_check +144  "prtyw   r3,r4"
func_check +148  "prtyd   r13,r14"
func_check +152  "mfcfar  r10"
func_check +156  "mtcfar  r11"
func_check +160  "cmpb    r3,r4,r5"
func_check +164  "lwzcix  r10,r11,r12"
func_check +168  "dadd    f16,f17,f18"
func_check +172  "daddq   f20,f22,f24"
func_check +176  "dss     3"
func_check +180  "dssall"
func_check +184  "dst     r5,r4,1"
func_check +188  "dstt    r8,r7,0"
func_check +192  "dstst   r5,r6,3"
func_check +196  "dststt  r4,r5,2"
func_check +200  "divwe   r10,r11,r12"
func_check +204  "divwe.  r11,r12,r13"
func_check +208  "divweo  r12,r13,r14"
func_check +212  "divweo. r13,r14,r15"
func_check +216  "divweu  r10,r11,r12"
func_check +220  "divweu. r11,r12,r13"
func_check +224  "divweuo r12,r13,r14"
func_check +228  "divweuo. r13,r14,r15"
func_check +232  "bpermd  r7,r17,r27"
func_check +236  "popcntw r10,r20"
func_check +240  "popcntd r10,r20"
func_check +244  "ldbrx   r20,r21,r22"
func_check +248  "stdbrx  r20,r21,r22"
func_check +252  "lfiwzx  f10,0,r10"
func_check +256  "lfiwzx  f10,r9,r10"
func_check +260  "fcfids  f4,f5"
func_check +264  "fcfids. f4,f5"
func_check +268  "fcfidus f4,f5"
func_check +272  "fcfidus. f4,f5"
func_check +276  "fctiwu  f4,f5"
func_check +280  "fctiwu. f4,f5"
func_check +284  "fctiwuz f4,f5"
func_check +288  "fctiwuz. f4,f5"
func_check +292  "fctidu  f4,f5"
func_check +296  "fctidu. f4,f5"
func_check +300  "fctiduz f4,f5"
func_check +304  "fctiduz. f4,f5"
func_check +308  "fcfidu  f4,f5"
func_check +312  "fcfidu. f4,f5"
func_check +316  "ftdiv   cr0,f10,f11"
func_check +320  "ftdiv   cr7,f10,f11"
func_check +324  "ftsqrt  cr0,f10"
func_check +328  "ftsqrt  cr7,f10"
func_check +332  "dcbtt   r8,r9"
func_check +336  "dcbtstt r8,r9"
func_check +340  "dcffix  f10,f12"
func_check +344  "dcffix. f20,f22"
func_check +348  "lbarx   r10,r11,r12"
func_check +352  "lbarx   r10,r11,r12"
func_check +356  "lbarx   r10,r11,r12,1"
func_check +360  "lharx   r20,r21,r22"
func_check +364  "lharx   r20,r21,r22"
func_check +368  "lharx   r20,r21,r22,1"
func_check +372  "stbcx.  r10,r11,r12"
func_check +376  "sthcx.  r10,r11,r12"
func_check +380  "fre     f14,f15"
func_check +384  "fre.    f14,f15"
func_check +388  "fres    f14,f15"
func_check +392  "fres.   f14,f15"
func_check +396  "frsqrte f14,f15"
func_check +400  "frsqrte. f14,f15"
func_check +404  "frsqrtes f14,f15"
func_check +408  "frsqrtes. f14,f15"
func_check +412  "isel    r2,r3,r4,28"
func_check +416  "dcbzl   r8,r9"
func_check +420  "frsqrtes f10,f11"
func_check +424  "dadd    f1,f2,f1"
func_check +428  "daddq   f0,f2,f0"
func_check +432  "dsub    f1,f2,f1"
func_check +436  "dsubq   f0,f2,f0"
func_check +440  "dmul    f1,f2,f1"
func_check +444  "dmulq   f0,f2,f0"
func_check +448  "ddiv    f1,f2,f1"
func_check +452  "ddivq   f0,f2,f0"
func_check +456  "dcmpu   cr1,f2,f1"
func_check +460  "dcmpuq  cr1,f2,f0"
func_check +464  "tabort. r5"
func_check +468  "tabortwc. 7,r8,r16"
func_check +472  "tabortdc. 20,r11,r10"
func_check +476  "tabortwci. 17,r10,-13"
func_check +480  "tabortdci. 29,r3,-5"
func_check +484  "tbegin."
func_check +488  "tcheck  cr7"
func_check +492  "tend."
func_check +496  "tendall."
func_check +500  "treclaim. r24"
func_check +504  "trechkpt."
func_check +508  "tsuspend."
func_check +512  "tresume."
func_check +516  "rfebb   0"
func_check +520  "rfebb"
func_check +524  "bctar-  12,4\\*cr5\\+gt"
func_check +528  "bctarl- 4,4\\*cr1\\+so"
func_check +532  "bctar\\+  12,4\\*cr3\\+lt"
func_check +536  "bctarl\\+ 4,eq"
func_check +540  "bctar   4,4\\*cr2\\+lt,1"
func_check +544  "bctarl  4,4\\*cr1\\+so,2"
func_check +548  "waitasec"
func_check +552  "msgsndp r8"
func_check +556  "mtsle   1"
func_check +560  "msgclrp r27"
func_check +564  "stqcx.  r10,r10,r12"
func_check +568  "stqcx.  r28,0,r7"
func_check +572  "lqarx   r24,r19,r11"
func_check +576  "lqarx   r22,0,r11"
func_check +580  "mfbhrbe r20,6"
func_check +584  "pbt.    r29,r17,r16"
func_check +588  "pbt.    r14,0,r7"
func_check +592  "clrbhrb"
func_check +596  "vpermxor v11,v10,v0,v23"
func_check +600  "vaddeuqm v24,v2,v7,v4"
func_check +604  "vaddecuq v10,v10,v8,v2"
func_check +608  "vsubeuqm v5,v15,v8,v19"
func_check +612  "vsubecuq v12,v31,v16,v29"
func_check +616  "vmulouw v20,v29,v13"
func_check +620  "vmuluwm v29,v0,v26"
func_check +624  "vaddudm v8,v21,v28"
func_check +628  "vmaxud  v1,v26,v1"
func_check +632  "vrld    v20,v3,v1"
func_check +636  "vcmpequd v4,v19,v11"
func_check +640  "vadduqm v23,v14,v30"
func_check +644  "vaddcuq v8,v8,v13"
func_check +648  "vmulosw v28,v27,v4"
func_check +652  "vmaxsd  v3,v4,v4"
func_check +656  "vmuleuw v0,v19,v21"
func_check +660  "vminud  v24,v20,v19"
func_check +664  "vcmpgtud v0,v28,v15"
func_check +668  "vmulesw v21,v0,v2"
func_check +672  "vminsd  v9,v26,v9"
func_check +676  "vsrad   v25,v29,v11"
func_check +680  "vcmpgtsd v11,v28,v11"
func_check +684  "bcdadd. v5,v8,v26,1"
func_check +688  "vpmsumb v4,v3,v12"
func_check +692  "bcdsub. v26,v31,v21,1"
func_check +696  "vpmsumh v5,v17,v16"
func_check +700  "vpkudum v23,v17,v20"
func_check +704  "vpmsumw v24,v21,v29"
func_check +708  "vpmsumd v9,v22,v13"
func_check +712  "vpkudus v18,v19,v18"
func_check +716  "vsubuqm v30,v16,v22"
func_check +720  "vcipher v14,v11,v7"
func_check +724  "vcipherlast v10,v2,v22"
func_check +728  "vgbbd   v23,v13"
func_check +732  "vsubcuq v16,v25,v16"
func_check +736  "vorc    v31,v1,v5"
func_check +740  "vncipher v4,v17,v31"
func_check +744  "vncipherlast v24,v2,v27"
func_check +748  "vbpermq v23,v21,v23"
func_check +752  "vpksdus v27,v18,v9"
func_check +756  "vnand   v27,v29,v27"
func_check +760  "vsld    v19,v19,v24"
func_check +764  "vsbox   v5,v13"
func_check +768  "vpksdss v25,v3,v7"
func_check +772  "vcmpequd. v28,v8,v0"
func_check +776  "vupkhsw v26,v26"
func_check +780  "vshasigmaw v5,v7,0,6"
func_check +784  "veqv    v28,v21,v14"
func_check +788  "vmrgow  v1,v8,v19"
func_check +792  "vshasigmad v0,v10,0,10"
func_check +796  "vsrd    v5,v27,v14"
func_check +800  "vupklsw v11,v13"
func_check +804  "vclzb   v14,v16"
func_check +808  "vpopcntb v20,v27"
func_check +812  "vclzh   v28,v11"
func_check +816  "vpopcnth v24,v9"
func_check +820  "vclzw   v27,v31"
func_check +824  "vpopcntw v17,v19"
func_check +828  "vclzd   v12,v29"
func_check +832  "vpopcntd v23,v22"
func_check +836  "vcmpgtud. v24,v20,v29"
func_check +840  "vcmpgtsd. v9,v6,v27"
func_check +844  "lxsiwzx vs62,r14,r26"
func_check +848  "lxsiwzx vs40,0,r25"
func_check +852  "lxsiwax vs25,0,r26"
func_check +856  "lxsiwax vs3,0,r3"
func_check +860  "mfvsrd  r12,vs62"
func_check +864  "mffprwz r20,f12"
func_check +868  "stxsiwx vs14,r9,r14"
func_check +872  "stxsiwx vs21,0,r8"
func_check +876  "mtvsrd  vs48,r11"
func_check +880  "mtvrwa  v31,r23"
func_check +884  "mtfprwz f16,r26"
func_check +888  "lxsspx  vs13,r19,r13"
func_check +892  "lxsspx  vs18,0,r13"
func_check +896  "stxsspx vs43,r2,r4"
func_check +900  "stxsspx vs55,0,r11"
func_check +904  "xsaddsp vs54,vs48,vs25"
func_check +908  "xsmaddasp vs14,vs50,vs1"
func_check +912  "xssubsp vs26,vs22,vs42"
func_check +916  "xsmaddmsp vs27,vs53,vs52"
func_check +920  "xsrsqrtesp vs8,vs59"
func_check +924  "xssqrtsp vs12,vs41"
func_check +928  "xsmulsp vs57,vs11,vs32"
func_check +932  "xsmsubasp vs38,vs20,vs26"
func_check +936  "xsdivsp vs26,vs19,vs6"
func_check +940  "xsmsubmsp vs35,vs37,vs55"
func_check +944  "xsresp  vs59,vs8"
func_check +948  "xsnmaddasp vs44,vs33,vs33"
func_check +952  "xsnmaddmsp vs17,vs62,vs30"
func_check +956  "xsnmsubasp vs54,vs52,vs31"
func_check +960  "xsnmsubmsp vs37,vs5,vs58"
func_check +964  "xxlorc  vs30,vs54,vs44"
func_check +968  "xxlnand vs49,vs14,vs29"
func_check +972  "xxleqv  vs62,vs22,vs30"
func_check +976  "xscvdpspn vs60,vs54"
func_check +980  "xsrsp   vs22,vs45"
func_check +984  "xscvuxdsp vs26,vs59"
func_check +988  "xscvsxdsp vs38,vs49"
func_check +992  "xscvspdpn vs59,vs26"
func_check +996  "fmrgow  f24,f14,f2"
func_check +1000 "fmrgew  f22,f7,f5"
